<template>
  <div>
    <div class="custom-wrap">
      <LazyLoadTab v-model="activeName" :tabMenus="menus"></LazyLoadTab>
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button size="small" type="primary" icon="el-icon-folder" @click="syncCarData">同步主机厂车辆数据</el-button>
      <el-button size="small" type="primary" icon="el-icon-folder" @click="saveVehicledetails">保存</el-button>
      <el-button size="small" type="primary" icon="el-icon-refresh-left" @click="closeDrawer">取消</el-button>
    </div>
  </div>
</template>

<script>
// import { protectRepair, brandsdict, coudImplVin, saveVehicle } from '@/api/repair/repairReception/customer/vehicleDetails';
import moment from 'moment';
export default {
  name: 'Vehicledetails',
  props: ['vehicleDetailsVin'],
  data() {
    this.dmsFunc = {};
    this.vehicleDetailsTotal = {};
    this.hadSync = false;
    return {
      activeName: '基本信息',
      menus: this.createMenus()
    };
  },
  mounted() {},
  created() {
    this.dmsFunc = { dmsFuncId: 35100010 };
    this.protectRepairFun(this.vehicleDetailsVin);
  },
  methods: {
    createMenus() {
      return [
        {
          title: '基本信息',
          path: 'repair/business/customer/vehicleDetails/tabs/baseInfo',
          params: {
            vin: this.vehicleDetailsVin
          },
          on: {
            formChangeHandle: val => {
              this.formChangeHandleMain(val);
            }
          }
        },
        {
          title: '保险保修',
          path: 'repair/business/customer/vehicleDetails/tabs/insuranceWarranty',
          params: {
            protectRepairInfo: {}
          },
          on: {
            insuranceChangeHandle: val => {
              this.formChangeHandleMain(val);
            }
          }
        },
        {
          title: '车辆备注',
          path: 'repair/business/customer/vehicleDetails/tabs/carRemark',
          params: {
            protectRepairInfo: {}
          },
          on: {
            remarkChangeHandle: val => {
              this.formChangeHandleMain(val);
            }
          }
        }
      ];
    },
    async protectRepairFun(val) {
      // const res = await protectRepair(this.dmsFunc, val);
      // this.menus.forEach(x => {
      //   x.params.protectRepairInfo = res;
      // });
      // this.vehicleDetailsTotal = res;
    },
    closeDrawer(type) {
      if (type === 'saveButton') {
        this.$emit('close', false, this.vehicleDetailsTotal);
      } else {
        this.$emit('close', false, null);
      }
    },
    formChangeHandleMain(val) {
      this.vehicleDetailsTotal = {
        ...this.vehicleDetailsTotal,
        ...val
      };
    },
    async syncCarData() {
      // if (this.vehicleDetailsTotal.BRAND === null || this.vehicleDetailsTotal.BRAND === '') {
      //   this.$notify.warning({ title: '提示信息', message: '请选择品牌！' });
      //   return;
      // }
      // const res = await brandsdict(this.dmsFunc, this.vehicleDetailsTotal.BRAND);
      // if (res === '12781002') {
      //   this.$notify.warning({ title: '提示信息', message: '非OEM品牌的车辆不需要同步！' });
      // }
      // const vinRes = await coudImplVin(this.dmsFunc, this.vehicleDetailsTotal.VIN);
      // this.hadSync = true;
      // if (vinRes.is_SEDMS004 == 'Y') {
      //   this.$confirm('VIN号在DCS系统无法同步，是否确认VIN号准确性？', '提示', {
      //     confirmButtonText: '确定',
      //     cancelButtonText: '取消',
      //     type: 'warning'
      //   })
      //     .then(() => {})
      //     .catch(() => {
      //       // this.$notify.info({title: '提示信息',message:'已取消删除'});
      //     });
      // }
    },
    async saveVehicledetails() {
      if (this.hadSync) {
        var params = {
          ArrearageAmount: this.vehicleDetailsTotal.ARREARAGE_AMOUNT,
          LastMaintainMileage: this.vehicleDetailsTotal.LAST_MAINTAIN_MILEAGE,
          LastMaintenanceDate: this.vehicleDetailsTotal.LAST_MAINTENANCE_DATE,
          LastMaintenanceMileage: this.vehicleDetailsTotal.LAST_MAINTENANCE_MILEAGE,
          address: this.vehicleDetailsTotal.ADDRESS,
          brand: this.vehicleDetailsTotal.BRAND,
          certificateNo: this.vehicleDetailsTotal.CERTIFICATE_NO,
          contactorGender: this.vehicleDetailsTotal.CONTACTOR_GENDER,
          deliverer: this.vehicleDetailsTotal.DELIVERER,
          delivererAddress: this.vehicleDetailsTotal.DELIVERER_ADDRESS,
          delivererGender: this.vehicleDetailsTotal.DELIVERER_GENDER,
          delivererMobile: this.vehicleDetailsTotal.DELIVERER_MOBILE,
          delivererPhone: this.vehicleDetailsTotal.DELIVERER_PHONE,
          dms_memoInfo: this.vehicleDetailsTotal.MEMO_INFO,
          firstInDate: this.vehicleDetailsTotal.FIRST_IN_DATE,
          insurance: [], // this.vehicleDetailsTotal.,
          license: this.vehicleDetailsTotal.LICENSE,
          mileage: this.vehicleDetailsTotal.MILEAGE,
          mobile: this.vehicleDetailsTotal.MOBILE,
          msgs: '', // this.vehicleDetailsTotal.,
          nextMaintainDate: this.vehicleDetailsTotal.NEXT_MAINTAIN_DATE,
          nextMaintainMileage: this.vehicleDetailsTotal.NEXT_MAINTAIN_MILEAGE,
          ownerName: this.vehicleDetailsTotal.OWNER_NAME,
          ownerNo: this.vehicleDetailsTotal.OWNER_NO,
          ownerProperty: this.vehicleDetailsTotal.OWNER_PROPERTY,
          phone: this.vehicleDetailsTotal.PHONE,
          prePay: this.vehicleDetailsTotal.PRE_PAY,
          salesMileage: this.vehicleDetailsTotal.SALES_MILEAGE,
          vin: this.vehicleDetailsTotal.VIN,
          productDate: moment(this.vehicleDetailsTotal.PRODUCT_DATE).format('YYYY-MM-DD'),
          zipCode: this.vehicleDetailsTotal.ZIP_CODE
        };
        // const res = await saveVehicle(params, { vin: this.vehicleDetailsTotal.VIN, ownerNo: this.vehicleDetailsTotal.OWNER_NO });
        // this.$notify.success({ title: '提示信息', message: '保存成功！' });
        // this.closeDrawer('saveButton');
      } else {
        this.syncCarData();
      }
    }
  }
};
</script>

<style lang="less">
.custom-wrap {
  height: calc(100vh - 145px);
  // position: relative;
}
</style>
